package com.dfec.water.controller;

import com.dfec.common.enums.BusinessType;
import com.dfec.common.utils.AjaxResult;
import com.dfec.framework.auth.custom.controller.AbstractController;
import com.dfec.framework.excel.service.ExcelService;
import com.dfec.framework.mybatis.core.page.PageParam;
import com.dfec.framework.mybatis.core.page.PageUtils;
import com.dfec.framework.operatelog.annotation.SysLog;
import com.dfec.water.entity.YdbWarnDeviceEntity;
import com.dfec.water.service.YdbWarnDeviceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 预警设备数据
 * @title: YdbDeviceTypeDictController
 * @author df
 * @date Thu Feb 06 11:10:12 CST 2025
 */
@Tag(name = "预警设备数据")
@RestController
@RequestMapping("warn/device")
public class YdbWarnDeviceController extends AbstractController {

    @Resource
    private YdbWarnDeviceService warnDeviceService;

    @Resource
    private  ExcelService excelService;

    /**
     * 分页查询
     */
    @PostMapping("/pageList")
    @Operation(summary = "分页查询")
    public AjaxResult<PageUtils<YdbWarnDeviceEntity>> pageList(@RequestBody PageParam<YdbWarnDeviceEntity> pageParam) {
        PageUtils page = warnDeviceService.queryPage(pageParam);
        return AjaxResult.ok().put(page);
    }


    /**
     * 不带分页查询
     */
    @PostMapping("/listAll")
    @Operation(summary = "全查")
    public AjaxResult<List<YdbWarnDeviceEntity>> listAll(@RequestBody YdbWarnDeviceEntity ydbDeviceTypeDict) {
        return AjaxResult.ok().put(warnDeviceService.listAll(ydbDeviceTypeDict));
    }


    /**
     * 保存
     */
    @SysLog(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    @Operation(summary = "新增")
    public AjaxResult save(@RequestBody YdbWarnDeviceEntity ydbDeviceTypeDict) {
        warnDeviceService.save(ydbDeviceTypeDict);
        return AjaxResult.ok();
    }

    /**
     * 修改
     */
    @SysLog(title = "修改", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @Operation(summary = "修改")
    public AjaxResult update(@RequestBody YdbWarnDeviceEntity ydbDeviceTypeDict) {
        warnDeviceService.updateById(ydbDeviceTypeDict);
        return AjaxResult.ok();
    }

    /**
     * 删除
     */
    @SysLog(title = "删除", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    @Operation(summary = "删除")
    public AjaxResult delete(@RequestBody Long[] ids) {
        warnDeviceService.removeByIds(Arrays.asList(ids));
        return AjaxResult.ok();
    }


    /**
     * 导入Excel
     */
    @PostMapping("/importExcel")
    public AjaxResult importExcel(@RequestParam MultipartFile file) {
        excelService.importExcel(file, YdbWarnDeviceEntity.class,1, warnDeviceService::saveBatch);
        return AjaxResult.ok();
    }


    /**
     * 导入出Excel
     */
    @PostMapping("/exportExcel")
    public void export(HttpServletResponse response) throws IOException {
        excelService.exportExcel(warnDeviceService.list(), YdbWarnDeviceEntity.class, response);
    }









}
